document.addEventListener('DOMContentLoaded', () => {
  const buttons = {
    pageView: document.getElementById('pageView'),
    scroll: document.getElementById('scroll'),
    outbound: document.getElementById('outbound'),
    search: document.getElementById('search'),
    form: document.getElementById('form'),
    video: document.getElementById('video'),
    download: document.getElementById('download')
  };

  // 注入测试代码到当前页面
  const injectTest = async (testCode) => {
    const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
    await chrome.scripting.executeScript({
      target: { tabId: tab.id },
      function: testCode
    });
  };

  // 测试函数
  buttons.pageView.onclick = () => injectTest(() => {
    window.location.href = window.location.href;
  });

  buttons.scroll.onclick = () => injectTest(() => {
    window.scrollTo(0, document.body.scrollHeight);
  });

  buttons.outbound.onclick = () => injectTest(() => {
    window.open('https://www.google.com', '_blank');
  });

  buttons.search.onclick = () => injectTest(() => {
    window.location.search = '?q=test';
  });

  buttons.form.onclick = () => injectTest(() => {
    const form = document.createElement('form');
    form.id = 'test-form';
    document.body.appendChild(form);
    form.submit();
    form.remove();
  });

  buttons.video.onclick = () => injectTest(() => {
    const video = document.querySelector('iframe[src*="youtube.com"]');
    if (video) {
      video.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
    }
  });

  buttons.download.onclick = () => injectTest(() => {
    const link = document.createElement('a');
    link.href = 'test.pdf';
    link.download = 'test.pdf';
    document.body.appendChild(link);
    link.click();
    link.remove();
  });
}); 